package com.magold.modifier;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.EntityModifier;

public class PositionSynchronizer extends EntityModifier {
	private IEntity mFollowingEntity;
	private float mDeltaX, mDeltaY;
	
	public PositionSynchronizer(IEntity pFollowingEntity, float pDeltaX, float pDeltaY) {
		mFollowingEntity = pFollowingEntity;
		mDeltaX = pDeltaX;
		mDeltaY = pDeltaY;
	}
		
	@Override
	public float getSecondsElapsed() {
		return 0.0f;
	}

	@Override
	public float getDuration() {
		return Float.MAX_VALUE;
	}

	@Override
	public float onUpdate(float pSecondsElapsed, IEntity pItem) {
		float px = mFollowingEntity.getX() + mDeltaX;
		float py = mFollowingEntity.getY() + mDeltaY;
		pItem.setPosition(px, py);
		
		return pSecondsElapsed;
	}

	@Override
	public PositionSynchronizer deepCopy() throws DeepCopyNotSupportedException {
		return new PositionSynchronizer(mFollowingEntity, mDeltaX, mDeltaY);
	}

	@Override
	public void reset() {
	}

}
